package com.youlin.controller;

import com.youlin.dto.*;
import com.youlin.dto.req.EditFHReqDto;
import com.youlin.entities.BygAdmin;
import com.youlin.entities.BygFarewellHall;
import com.youlin.service.BygFarewellHallService;
import com.youlin.untils.AdminUtil;
import com.youlin.untils.MyBeanUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 告别厅管理
 */
@ApiSort(5)
@Api(tags = {"5 - 告别厅管理"})
@RestController
@RequestMapping("/bygFarewellHall")
public class BygFarewellHallController {

    @Autowired
    private BygFarewellHallService bygFarewellHallService;

    /**
     * 获取全部告别厅信息列表
     * @param baseReqDto
     * @return
     */
    @PostMapping("/findAllFHs")
    @ApiOperationSort(value = 1)
    @ApiOperation(value = "1 - 获取全部告别厅信息列表", notes = "请求参数：data = 单位ID")
    public PageDataResDto<List<BygFarewellHall>> findAllFHs (@RequestBody PageDataReqDto<Integer> baseReqDto) {
        Integer unitId = baseReqDto.getData();
        if (unitId == null) return new PageDataResDto<>(Status.PARAMETERERROR);
        return bygFarewellHallService.findPageFHs(unitId, baseReqDto.getPageInfo());
    }

    /**
     * 新建或修改告别厅信息
     * @param baseReqDto
     * @return
     */
    @PostMapping("/editFH")
    @ApiOperationSort(value = 2)
    @ApiOperation(value = "2 - 新建或修改告别厅信息", notes = "响应参数：status-message = {1011-告别厅名称重复}")
    public BaseResDto<Status, String> editFH (@RequestBody BaseReqDto<EditFHReqDto> baseReqDto) {
        EditFHReqDto data = baseReqDto.getData();
        if (MyBeanUtil.isParamError(data)) return new BaseResDto<>(Status.PARAMETERERROR);
        return bygFarewellHallService.editFH(data);
    }

    /**
     * 逻辑删除告别厅信息
     * @param baseReqDto
     * @return
     */
    @PostMapping("/delFHById")
    @ApiOperationSort(value = 3)
    @ApiOperation(value = "3 - 逻辑删除告别厅信息", notes = "请求参数：data = 告别厅ID\n" +
            "响应参数：status-message = {1020-不能删除举行过告别会的告别厅}")
    public BaseResDto<Status, String> delFHById (@RequestBody BaseReqDto<Integer> baseReqDto) {
        Integer fhId = baseReqDto.getData();
        if (fhId == null) return new BaseResDto<>(Status.PARAMETERERROR);
        return bygFarewellHallService.delFHById(fhId);
    }

}

